from django.shortcuts import render,redirect
from django.http import HttpResponse
import myadmin
models = myadmin.models

# 商场主页面
def shopinfo(request):
    id = request.GET.get('gid')
    goodsinfo = models.Goods.objects.get(id=id)
    content = {'goods': goodsinfo}
    return render(request,'myhome/shopInfo.html',content)

# 商品列表
def shoplist(request,cid,gid):
    # 根据参数选择当前是哪一个一级分类
    ob1 = models.Category.objects.get(id=cid)
    # 当前一级分类下的所有二级分类
    ob2 = models.Category.objects.filter(cid=cid)
    # 遍历当前一级分类下的所有二级分类
    goods = []
    goodsid = int(gid)
    for c in ob2:
        # 判度是否是一级分类
        if goodsid == 0:
            # 一级分类
            goods.append(c.goods_set.all())
        else:
            if c.id == goodsid:
                goods.append(c.goods_set.all())
    content = {'cate1':ob1,'cate2':ob2,'goods':goods,'color':goodsid}
    return render(request,'myhome/shopList.html',content)

# 购物车
def shopcart(request):
    return render(request, 'myhome/shopCart.html')

# 支付
def pay(request):
    return render(request, 'myhome/pay.html')

# 手机端演示
def mobile(request):
    return render(request,'myhome/mobile.html')